const express = require('express');
const router = express.Router();
const HealthRecord = require('../models/HealthRecord');

// 获取指定老人的健康记录
router.get('/health-records/:residentId', async (req, res) => {
    try {
        const healthRecords = await HealthRecord.findAll({
            where: { residentId: req.params.residentId }
        });
        res.json({
            success: true,
            data: healthRecords
        });
    } catch (error) {
        res.status(500).json({
            success: false,
            message: error.message
        });
    }
});

// 添加健康记录
router.post('/add-health-record', async (req, res) => {
    try {
        const healthRecord = await HealthRecord.create(req.body);
        res.status(201).json({
            success: true,
            data: healthRecord
        });
    } catch (error) {
        res.status(400).json({
            success: false,
            message: error.message
        });
    }
});

module.exports = router; 